﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PsychveyApp1.classes;
using System.Collections;

namespace PsychveyApp1
{
    public partial class DisplayedInformationSheet : System.Web.UI.Page
    {
        TableRow row = new TableRow();
        TableCell cell = new TableCell();
        ArrayList conditionCheckboxArray = new ArrayList();

        protected void Page_Load(object sender, EventArgs e)
        {
            lblSurveyID.Text = Session["displayinfosheetsurveyid"].ToString();
            lblDate.Text = "Date: " + DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year + "-" + DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString();
            Image1.ImageUrl = DBManager.GetImageURL(Session["displayinfosheetsurveyid"].ToString());
            TextBox1.Text = DBManager.GetInformationSheetText(Session["displayinfosheetsurveyid"].ToString());
            TextBox2.Text = DBManager.GetInformationConsentForm(Session["displayinfosheetsurveyid"].ToString());



            ArrayList listOfConditions = DBManager.GetListOfConditions(Session["displayinfosheetsurveyid"].ToString());
            conditionCheckboxArray = new ArrayList();
            for (int j = 0; j < listOfConditions.Count; j++)
            {
                row = new TableRow();
                cell = new TableCell();
                CheckBox cbxConditionCheckbox = new CheckBox();
                conditionCheckboxArray.Add(cbxConditionCheckbox);
                cbxConditionCheckbox.Text = ((InformationConditionConsent)listOfConditions[j]).checkboxText;
                cbxConditionCheckbox.Font.Bold = true;
                cbxConditionCheckbox.Font.Size = FontUnit.Medium;
                cbxConditionCheckbox.TextAlign = TextAlign.Right;
                cell.Controls.Add(cbxConditionCheckbox);
                row.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Justify;
                row.Cells.Add(cell);
                textboxTable2.Rows.Add(row);
            }
            this.Panel2.Controls.Add(textboxTable2);
        }

        protected void btnProceedSurvey_Click(object sender, EventArgs e)
        {
            ArrayList listOfConditions = DBManager.GetListOfConditions(Session["displayinfosheetsurveyid"].ToString());
            bool proceed = true;
            if ((!CheckBox1.Checked) || (!CheckBox2.Checked) || (!CheckBox3.Checked))
            {
                proceed = false;
            }
                    
            for (int j = 0; j < listOfConditions.Count ; j++)
            {
                if (!((CheckBox)(conditionCheckboxArray[j])).Checked)
                {
                    proceed = false;
                }
                
            }

            if(proceed == true)
            {
                Server.Transfer("AnswerSurvey.aspx?" + Session["surveyid"]);
            }
            else
            {
                lblErrorMessage.Text = "Please tick all the checkboxes to proceed";
            }
        }
    }
}